package com.cryptape.cita_wallet.activity;

import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.cryptape.cita_wallet.bean.MessageBean;
import com.cryptape.cita_wallet.event.CurrencyRefreshEvent;
import com.cryptape.cita_wallet.view.SettingButtonView;
import com.cryptape.cita_wallet.view.TitleBar;
import com.mangoworld.android.R;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

;

/**
 * Created by dengming on 13/1/20.
 */

public class MessageListActivity extends NBaseActivity {

    private RecyclerView messageListRecycler;
    private List<MessageBean> messageArray = new ArrayList<>();
    private TitleBar title;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_message_list;
    }

    @Override
    protected void initView() {
        messageListRecycler = findViewById(R.id.rv_message_list);
        title = findViewById(R.id.title);
    }

    @Override
    protected void initData() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        messageListRecycler.setLayoutManager(linearLayoutManager);

        Adapter adapter = new Adapter();
        messageListRecycler.setAdapter(adapter);
        title.setOnLeftClickListener(() -> finish());
    }

    @Override
    protected void initAction() {

    }

    class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder> {

        @NonNull
        @Override
        public Adapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_currency, parent, false);
            return new Adapter.ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull Adapter.ViewHolder holder, int position) {
//            Currency currency = currencyArray.get(position);
//            if (SharePrefUtil.getString(ConstantUtil.CURRENCY, ConstantUtil.DEFAULT_CURRENCY).equals(currency.getName())) {
//                holder.currency.setRightImageShow(true);
//            } else {
//                holder.currency.setRightImageShow(false);
//            }
//            holder.currency.setNameText(currency.getName());
//            holder.currency.setOnClickListener(() -> {
//                SharePrefUtil.putString(ConstantUtil.CURRENCY, currency.getName());
//                notifyDataSetChanged();
//                finish();
//            });
        }

        @Override
        public int getItemCount() {
            return messageArray.size();
        }

        public class ViewHolder extends RecyclerView.ViewHolder {

            ConstraintLayout root;
            SettingButtonView currency;

            public ViewHolder(View view) {
                super(view);
                currency = view.findViewById(R.id.currency);
                root = view.findViewById(R.id.root);
            }
        }
    }

    @Override
    public void finish() {
        setResult(RESULT_OK);
        EventBus.getDefault().post(new CurrencyRefreshEvent());
        super.finish();
    }

}

